﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using zyconfig;

namespace zymain
{
    public partial class FrmUserm : Form
    {
        public BindingSource BookData;
        private DataTable dt = new DataTable();
        private string uid;
        private int _uid;
        public FrmUserm()
        {
            InitializeComponent();
        }
        private void AddUser()
        {
            using (DbOperHandler _open = new Common().Doh())
            {
                _open.Reset();
                _open.SqlCmd = "select * from 系统用户信息 order by 用户代码";
                this.dt = _open.GetDataTable();
                this.BookData = new BindingSource();
                this.dataGridBook.AutoGenerateColumns = false;
                this.BookData.DataSource = dt;
                this.binNavBook.BindingSource = this.BookData;
                this.dataGridBook.DataSource = this.BookData;
                if (this.BookData.Count <= 0)
                {
                    MessageBox.Show("没有检索到记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.dataGridBook.Rows[0].Selected=true;
                    this.uid = this.dataGridBook.Rows[0].Cells[0].Value.ToString();
                    this._uid = Convert.ToInt32(this.dataGridBook.Rows[0].Cells[0].Value.ToString());
                }
            }
        }
        private void FrmUserm_Load(object sender, EventArgs e)
        {
            string formName = "FrmTool";
            Form fr = Application.OpenForms[formName];
            if (fr != null)
            {
                FrmTool f1 = (FrmTool)fr;
                this.uid = f1.UserID;
            }
            this.AddUser();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FrmUser fr = new FrmUser();
            fr.uid = this._uid;
            fr.ShowDialog();
        }

        private void dataGridBook_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridBook.SelectedRows != null && this.dataGridBook.SelectedRows.Count > 0)
            {
                this.uid = this.dataGridBook.SelectedRows[0].Cells[0].Value.ToString();
                this._uid = Convert.ToInt32(this.dataGridBook.SelectedRows[0].Cells[0].Value.ToString());
            }
        }
    }
}
